package com.wdz.fifter;


import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

import java.util.List;

/**
 * 配置类：注册拦截器，过滤器
 */
@Configuration
public class WebAppConfig implements WebMvcConfigurer {
    //排除不需要拦截的请求
    public static List<String> pathPatterns;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getRequestInterceptor()).addPathPatterns("/**");
    }

    /**
     * 注册过滤器
     * @return
     */
    @SuppressWarnings({ "rawtypes", "unchecked" })
    @Bean
    public FilterRegistrationBean filterRegist() {
        FilterRegistrationBean frBean = new FilterRegistrationBean();
        frBean.setFilter(new MyFifter());
        frBean.addUrlPatterns("/*");
        return frBean;
    }
    @Bean
    public RequestInterceptor getRequestInterceptor(){return new RequestInterceptor();}
}
